package utils;

import java.io.BufferedReader;
import java.io.IOException;

/**
 * BufferedReader with push back
 *
 */

public class LinesReader {

	private BufferedReader _bufr;
	private String _lastLine;
	private boolean _returnOld;
	
	public LinesReader(BufferedReader bufr) {
		_bufr = bufr;
	}
	
	/**
	 * reads new line or returns previous if _returnOld was <code>true</code>
	 * @return new line from {@link BufferedReader} _bufr
	 * @throws IOException
	 */
	public String readLine() throws IOException {
		if (_returnOld) {
			_returnOld = false;
			return _lastLine;
		} else {
			_lastLine = _bufr.readLine();
			return _lastLine;
		}
	}

	void pushBack() {
		_returnOld = true;
	}
	
}
